#include "ag.h"
#include "trustzone.h"

extern void _jump64(UINT32 AtfEntry, UINT32 Argument1, UINT32 Argument2, UINT32 AtfArgPtr, UINT32 LkEntry) NO_RETURN;
extern VOID AgpPrepareToJump();
extern UINT32 _bootinfo;
extern UINT32 _bootinfo_length;

VOID AgpBootAtf(
	PVOID AtfBase UNUSED,
	SIZE AtfSize UNUSED,
	PVOID AtfEntry,
	PVOID TeeBase,
	SIZE TeeSize,
	PVOID TeeEntry,
	PVOID LkBase,
	SIZE LkSize,
	PVOID LkEntry)
{
	// currently we skip any hardware initialization as preloader has already done that
	// at least if we have been booted using BOOT_IMAGE command
	// currently we assume so

	// FIXME: Currently we do not support TEE
	ASSERT(TeeBase == NULL);
	ASSERT(TeeSize = 0);
	ASSERT(TeeEntry == NULL);

	ATF_BOOTARG Arg;
	Arg.Magic = ATF_BOOTCFG_MAGIC;
	Arg.TeeSupport = 0;
	Arg.TeeEntry = 0;
	Arg.TeeBootArgumentAddress = 0;

	// FIXME: hardcoded fake values
	Arg.HwUniqueId[0] = 0x4d0102d4;
	Arg.HwUniqueId[1] = 0x0102d44d;
	Arg.HwUniqueId[2] = 0xf0000f0f;
	Arg.HwUniqueId[3] = 0xf0f0000f;
	Arg.HwRandomId[0] = 0x00ff00ff;
	Arg.HwRandomId[1] = 0xff00ff00;
	Arg.AtfIrqNumber = 293 + 32;

	// FIXME: hardcoded fake values
	Arg.DeviceInfo[0] = 0;
	Arg.DeviceInfo[1] = 0;
	Arg.DeviceInfo[2] = 0;
	Arg.DeviceInfo[3] = 0;

	// TODO: allow user to set these during runtime
	Arg.AtfLogPort = 0x11003000; // UART 1
	Arg.AtfLogBaudrate = 921600;
	Arg.AtfLogBufferBase = 0;
	Arg.AtfLogBufferSize = 0;
	Arg.AtfAeeDebugBufferBase = 0;
	Arg.AtfAeeDebugBufferSize = 0;

	AgpPrepareToJump();
	_jump64((UINT32)AtfEntry, _bootinfo, _bootinfo_length, (UINT32)&Arg, (UINT32)LkEntry);
}
